package cn.ll.po;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * A data access object (DAO) providing persistence and search support for
 * CurrencyRate entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see cn.ll.po.CurrencyRate
 * @author MyEclipse Persistence Tools
 */

public class CurrencyRateDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(CurrencyRateDAO.class);
	// property constants
	public static final String CURRENCY_DESC = "currencyDesc";
	public static final String RATE = "rate";
	public static final String REMARK = "remark";

	protected void initDao() {
		// do nothing
	}

	public void save(CurrencyRate transientInstance) {
		log.debug("saving CurrencyRate instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(CurrencyRate persistentInstance) {
		log.debug("deleting CurrencyRate instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public void update(CurrencyRate persistentInstance) {
		log.debug("update CurrencyRate instance");
		try {
			getHibernateTemplate().update(persistentInstance);
			log.debug("update successful");
		} catch (RuntimeException re) {
			log.error("update failed", re);
			throw re;
		}
	}
	
	public CurrencyRate findById(java.lang.String id) {
		log.debug("getting CurrencyRate instance with id: " + id);
		try {
			CurrencyRate instance = (CurrencyRate) getHibernateTemplate().get(
					"cn.ll.po.CurrencyRate", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<CurrencyRate> findByExample(CurrencyRate instance) {
		log.debug("finding CurrencyRate instance by example");
		try {
			List<CurrencyRate> results = (List<CurrencyRate>) getHibernateTemplate()
					.findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding CurrencyRate instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from CurrencyRate as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<CurrencyRate> findByCurrencyDesc(Object currencyDesc) {
		return findByProperty(CURRENCY_DESC, currencyDesc);
	}

	public List<CurrencyRate> findByRate(Object rate) {
		return findByProperty(RATE, rate);
	}

	public List<CurrencyRate> findByRemark(Object remark) {
		return findByProperty(REMARK, remark);
	}

	public List findAll() {
		log.debug("finding all CurrencyRate instances");
		try {
			String queryString = "from CurrencyRate";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public CurrencyRate merge(CurrencyRate detachedInstance) {
		log.debug("merging CurrencyRate instance");
		try {
			CurrencyRate result = (CurrencyRate) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(CurrencyRate instance) {
		log.debug("attaching dirty CurrencyRate instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(CurrencyRate instance) {
		log.debug("attaching clean CurrencyRate instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static CurrencyRateDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (CurrencyRateDAO) ctx.getBean("CurrencyRateDAO");
	}
}